home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / sonson.c < prev    next >
C/C++ Source or Header  |  1998-07-29  |  5KB  |  155 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *sonson_scrollx;
  14.  
  15.  
  16.  
  17. /***************************************************************************
  18.  
  19.   Convert the color PROMs into a more useable format.
  20.  
  21.   Son Son has two 32x8 palette PROMs and two 256x4 lookup table PROMs (one
  22.   for characters, one for sprites).
  23.   The palette PROMs are connected to the RGB output this way:
  24.  
  25.   I don't know the exact values of the resistors between the PROMs and the
  26.   RGB output. I assumed these values (the same as Commando)
  27.   bit 7 -- 220 ohm resistor  -- GREEN
  28.         -- 470 ohm resistor  -- GREEN
  29.         -- 1  kohm resistor  -- GREEN
  30.         -- 2.2kohm resistor  -- GREEN
  31.         -- 220 ohm resistor  -- BLUE
  32.         -- 470 ohm resistor  -- BLUE
  33.         -- 1  kohm resistor  -- BLUE
  34.   bit 0 -- 2.2kohm resistor  -- BLUE
  35.  
  36.   bit 7 -- unused
  37.         -- unused
  38.         -- unused
  39.         -- unused
  40.         -- 220 ohm resistor  -- RED
  41.         -- 470 ohm resistor  -- RED
  42.         -- 1  kohm resistor  -- RED
  43.   bit 0 -- 2.2kohm resistor  -- RED
  44.  
  45. ***************************************************************************/
  46. void sonson_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  47. {
  48.     int i;
  49.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  50.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  51.  
  52.  
  53.     for (i = 0;i < Machine->drv->total_colors;i++)
  54.     {
  55.         int bit0,bit1,bit2,bit3;
  56.  
  57.  
  58.         /* red component */
  59.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  60.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  61.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  62.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  63.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  64.         /* green component */
  65.         bit0 = (color_prom[0] >> 4) & 0x01;
  66.         bit1 = (color_prom[0] >> 5) & 0x01;
  67.         bit2 = (color_prom[0] >> 6) & 0x01;
  68.         bit3 = (color_prom[0] >> 7) & 0x01;
  69.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  70.         /* blue component */
  71.         bit0 = (color_prom[0] >> 0) & 0x01;
  72.         bit1 = (color_prom[0] >> 1) & 0x01;
  73.         bit2 = (color_prom[0] >> 2) & 0x01;
  74.         bit3 = (color_prom[0] >> 3) & 0x01;
  75.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  76.  
  77.         color_prom++;
  78.     }
  79.  
  80.     color_prom += Machine->drv->total_colors;
  81.     /* color_prom now points to the beginning of the lookup table */
  82.  
  83.     /* characters use colors 0-15 */
  84.     for (i = 0;i < TOTAL_COLORS(0);i++)
  85.         COLOR(0,i) = *(color_prom++) & 0x0f;
  86.  
  87.     /* sprites use colors 16-31 */
  88.     for (i = 0;i < TOTAL_COLORS(1);i++)
  89.         COLOR(1,i) = (*(color_prom++) & 0x0f) + 0x10;
  90. }
  91.  
  92.  
  93.  
  94. /***************************************************************************
  95.  
  96.   Draw the game screen in the given osd_bitmap.
  97.   Do NOT call osd_update_display() from this function, it will be called by
  98.   the main emulation engine.
  99.  
  100. ***************************************************************************/
  101. void sonson_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  102. {
  103.     int offs;
  104.  
  105.  
  106.     /* for every character in the Video RAM, check if it has been modified */
  107.     /* since last time and update it accordingly. */
  108.     for (offs = videoram_size - 1;offs >= 0;offs--)
  109.     {
  110.         if (dirtybuffer[offs])
  111.         {
  112.             int sx,sy;
  113.  
  114.  
  115.             dirtybuffer[offs] = 0;
  116.  
  117.             sx = offs % 32;
  118.             sy = offs / 32;
  119.  
  120.             drawgfx(tmpbitmap,Machine->gfx[0],
  121.                     videoram[offs] + 256 * (colorram[offs] & 3),
  122.                     colorram[offs] >> 2,
  123.                     0,0,
  124.                     8*sx,8*sy,
  125.                     0,TRANSPARENCY_NONE,0);
  126.         }
  127.     }
  128.  
  129.  
  130.     /* copy the background graphics */
  131.     {
  132.         int i,scroll[32];
  133.  
  134.  
  135.         for (i = 0;i < 5;i++)
  136.             scroll[i] = 0;
  137.         for (i = 5;i < 32;i++)
  138.             scroll[i] = -(*sonson_scrollx);
  139.  
  140.         copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  141.     }
  142.  
  143.  
  144.     /* draw the sprites */
  145.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  146.     {
  147.         drawgfx(bitmap,Machine->gfx[1],
  148.                 spriteram[offs + 2] + ((spriteram[offs + 1] & 0x20) << 3),
  149.                 spriteram[offs + 1] & 0x1f,
  150.                 ~spriteram[offs + 1] & 0x40,~spriteram[offs + 1] & 0x80,
  151.                 spriteram[offs + 3],spriteram[offs + 0],
  152.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  153.     }
  154. }
  155.